package com.ostrich.cloud.ostrichBusinessWeb.app.Api;


import cn.hutool.core.bean.BeanUtil;
import com.ostrich.cloud.common.result.PageResult;
import com.ostrich.cloud.common.result.Result;
import com.ostrich.cloud.ostrichBusinessWeb.app.Utlis.UserId;
import com.ostrich.cloud.ostrichBusinessWeb.client.BusinessWebClient;
import com.ostrich.cloud.ostrichBusinessWeb.client.param.BusinessUpdateParam;
import com.ostrich.cloud.ostrichGoodsSercice.model.Dto.SalesDto;
import com.ostrich.cloud.ostrichGoodsSercice.model.param.GetSalesParam;
import com.ostrich.cloud.ostrichGoodsService.client.SalesClient;
import com.ostrich.cloud.ostrichGoodsService.client.TypeClient;
import com.ostrich.cloud.ostrichUserService.client.BusinessmanMangerClient;
import com.ostrich.cloud.ostrichUserService.client.RiderMangerClient;
import com.ostrich.ostrichUserService.param.bussiness.LoginBusParam;
import com.ostrich.ostrichUserService.param.bussiness.UpdateBusParam;
import org.springframework.web.bind.annotation.RestController;

import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.io.IOException;
import java.util.Date;

@RestController
public class BusinessWebApiImp implements BusinessWebClient {


    @Resource
    private BusinessmanMangerClient businessmanMangerClient;

    @Resource
    private RiderMangerClient riderMangerClient;


    @Resource
    private TypeClient typeClient;
    @Resource
    private SalesClient salesClient;
    @Override
    public Result getBusiness() {
        Result onlyBusiness = businessmanMangerClient.getOnlyBusiness();
        return onlyBusiness;
    }

    @Override
    public Result getRiderByBusiness(Integer current,Integer size,String status) {

        int i = UserId.getParentId();
        Result allRider = riderMangerClient.getAllRider(current, size, status, i);

        return allRider;
    }

    @Override
    public Result businessLogin(String username, String password) {
        LoginBusParam param=new LoginBusParam();
        param.setUsername(username);
        param.setPassword(password);
        Result result = businessmanMangerClient.businessmanLogin(param);
        return result;
    }

    @Override
    public Result putBusiness(BusinessUpdateParam param) {

        UpdateBusParam updateBusParam= BeanUtil.copyProperties(param,UpdateBusParam.class);
        int i = UserId.getParentId();
        updateBusParam.setBusinessmanId(i);
        Result result = businessmanMangerClient.updateBusinessMessage(updateBusParam);

        return result;
    }

    @Override
    public Result conditionsQuerySales(Date startTime, Date endTime, Integer current, Integer size) {

        GetSalesParam param=new GetSalesParam();
        param.setCurrent(current);
        param.setSize(size);
        param.setStartTime(startTime);
        param.setEndTime(endTime);
        PageResult<SalesDto> salesDtoPageResult = salesClient.conditionsQuerySales(param);


        return salesDtoPageResult;
    }

    @Override
    public Result upLoad(MultipartFile file) throws IOException {

        String s = typeClient.upLoad(file);
        return Result.ok(s);
    }


}
